package com.hanlp.top_interview_150.数组;

/**
 * 189. 轮转数组
 */
public class A06 {
    public static void main(String[] args) {
        int[] arr = new int[]{1,2,3,4,5,6,7};
        rotate(arr,3);
        System.out.println(arr);
    }

    public static void rotate(int[] nums, int k) {
        if(k>=nums.length){
            k = k%nums.length;
        }
        if(k == 0){
            return;
        }
        int[] end = new int[k];
        for(int i = 0; i < k ; i++){
            end[i] = nums[nums.length -k + i];
        }
        for(int i = nums.length ; i > k ; i-- ){
            nums[i-1] = nums[i-1-k];
        }
        for(int i = 0; i<k ; i++){
            nums[i] = end[ i ];
        }
    }
}
